﻿<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
	<css href="__STATICS__/css/bootstrap.min.css" />
	<css href="__STATICS__/css/common.css" />
	<css href="__STATICS__/css/site.css" />
	<css href="__STATICS__/css/iconfont.css" />
	<css href="__STATICS__/css/nav-help.css" />
	<css href="__STATICS__/css/font-awesome.min.css" />
	<css href="__STATICS__/plugins/umeditor/themes/default/css/umeditor.css"/>
	<css href="__STATICS__/plugins/select2/css/select2.min.css" />
	<style type="text/css">
		body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
	</style>
	<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=A1LU7iHS0avqQwPLAxbhKn0UYSQCuRVH"></script>
	<title>获取覆盖物的信息</title>
</head>
<body>
	 <div id="map-dialog" class="modal fade in" tabindex="-1" role="dialog" aria-hidden="true" style="display: block; padding-right: 6px;">
		 <div class="modal-dialog we7-modal-dialog" style="width: 100%;">	
		 	<div class="modal-content" >
		 		<div class="modal-header"style='margin-top:30px'>	
		 			<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>	<h3>请选择地点</h3>
		 		</div>
				<div class="modal-body">
				 	<div class="form-group">
						<div class="input-group">
				 			<input type="text" id='cityName' class="form-control" placeholder="请输入地址来直接查找相关位置" onkeydown="press(event)">
							<div class="input-group-btn"><button onclick='theLocation()' class="btn btn-default"> 搜索</button></div>
				 		</div>
				 	</div>
					<div id="map-container" style="height: 380px; overflow: hidden; position: relative; z-index: 0; background-color: rgb(243, 241, 236); color: rgb(0, 0, 0); text-align: left;">
					
					</div>
				</div>
				<div class="modal-footer">
					当前坐标&nbsp;&nbsp;&nbsp;
					经度：<input type='text' name='g_lng' value='{$lng}' style="width:120px" readonly>&nbsp;&nbsp;&nbsp;
					纬度：<input type='text' name='g_lat' value='{$lat}' style="width:120px" readonly>
					<button type="button" class="btn btn-default" onclick='guanbi();'>取消</button>
					<button type="button" class="btn btn-primary" onclick="getp();">确认</button>
				</div>	
		 	</div>
		 </div>
	 </div>
	<js href="__STATICS__/js/jquery-1.11.1.min.js"/>
	<js href="__STATICS__/plugins/layer/layer.js"/>
	<script type="text/javascript">
		// 百度地图API功能
		var map = new BMap.Map("map-container");
		var point = new BMap.Point(116.403851,39.915177);
		map.centerAndZoom(point,13);
		
		
		var g_lng="{$lng}";
		var g_lat="{$lat}";
		if(g_lng!=''&&g_lat!=''){
			var point = new BMap.Point(g_lng,g_lat);
			map.centerAndZoom(point,13);
			var marker = new BMap.Marker(point);  // 创建标注
			getmap(marker);
		}else{
			var geolocation = new BMap.Geolocation();
			geolocation.getCurrentPosition(function(r){
				if(this.getStatus() == BMAP_STATUS_SUCCESS){
					var marker = new BMap.Marker(r.point);
					$(":text[name='g_lng']").val(r.point.lng);
					$(":text[name='g_lat']").val(r.point.lat);
					map.panTo(r.point);
					getmap(marker);
				}
				else {
					alert('failed'+this.getStatus());
				}        
			},{enableHighAccuracy: true})
		}
		
		
		
		 function press(event){
			 if(event.keyCode==13){ 
				 theLocation(); 
			 }
		 }
		function theLocation(){
			map.clearOverlays();       
			var city = document.getElementById("cityName").value;
			if(city != ""){
				map.centerAndZoom(city,13);      // 用城市名设置地图中心点
				// 创建地址解析器实例
				var myGeo = new BMap.Geocoder();
				// 将地址解析结果显示在地图上,并调整地图视野
				myGeo.getPoint(city, function(point){
					if (point) {
						map.centerAndZoom(point, 13);
						var marker = new BMap.Marker(point);  // 创建标注
						getmap(marker);
					}else{
						alert("您选择地址没有解析到结果!");
					}
				}, "北京市");
			}
		}
		function getmap(marker){
			map.enableScrollWheelZoom();   //启用滚轮放大缩小，默认禁用
			map.enableContinuousZoom();    //启用地图惯性拖拽，默认禁用
			map.addOverlay(marker);
			marker.enableDragging();
			var label = new BMap.Label("移动标记,选择坐标",{offset:new BMap.Size(20,-10)});
			marker.setLabel(label);
			marker.setAnimation(BMAP_ANIMATION_BOUNCE), setTimeout(function() {
				marker.setAnimation(null)
			}, 3600); //跳动的动画
			// 将标注添加到地图中
			marker.addEventListener("dragend",getAttr);
			function getAttr(){
				var p = marker.getPosition();       //获取marker的位置
				$(":text[name='g_lng']").val(p.lng);
				$(":text[name='g_lat']").val(p.lat);
			}
		}
		function guanbi(){
			var index = parent.layer.getFrameIndex(window.name);
			parent.layer.close(index);
		}
		function getp(){
			parent.$(":text[name='enterprise_gc_lng']").val($(":text[name='g_lng']").val());
			parent.$(":text[name='enterprise_gc_lat']").val($(":text[name='g_lat']").val());
			guanbi();
		}
	</script>
</body>
</html>